import layout from "@/view/home/index";
import BlankPage from "@/view/blankpage"


// 将后端传回的component 的字符串模式，改为我们前端路由需要的component模式
function loadPageByRoutes(str) {
    return function (resolve) {
        require([`@/view${str}`], resolve);
    };
};

// 递归路由
export default function getAddRoutes(data) {
    data.forEach((item) => {
        if (item.component == "layout") {
            item.component = layout;
        } else if (item.component == "BlankPage") {
            item.component = BlankPage;
        } else {
            item.component = loadPageByRoutes(item.component);
        }
        if (item.children && item.children.length > 0) {
            getAddRoutes(item.children);
        }
    });
};